//****************************************************wbox.js begin************************************************************************************************
(function($){
    //class为.wBox_close为关闭
    $.fn.wBox = function(options){
        var defaults = {
            wBoxURL: STATIC+"/box/",
            opacity: 0.5,//背景透明度
            callBack: null,
            noTitle: false,
            show:false,
            timeout:0,
            target:null,
            requestType:null,//iframe,ajax,img
            postdata:null,
            title: "",
            drag:true,
            iframeWH: {//iframe 设置高宽
                width: 300,
                height: 50
            },
            html: ''//wBox内容
        },_this=this;
        this.YQ = $.extend(defaults, options);
        var  wBoxHtml = '<div id="wBox"><div class="wBox_popup"><table><tbody><tr><td><div class="wBox_body">' + (_this.YQ.noTitle ? '' : '<table class="wBox_title"><tr><td class="wBox_dragTitle"><div class="wBox_itemTitle">' + _this.YQ.title + '</div></td><td width="20px" title="关闭"><div class="wBox_close"></div></td></tr></table> ') +
        '<div class="wBox_content" id="wBoxContent"></div></div></td></tr></tbody></table></div></div>', B = null, C = null, $win = $(window),$t=$(this);//B背景，C内容jquery div   
        this.showBox=function (){
            $("#wBox_overlay").remove();
            $("#wBox").remove();
            
            B = $("<div id='wBox_overlay' style='min-width:1200px;' class='wBox_hide'></div>").hide().addClass('wBox_overlayBG').css('opacity', _this.YQ.opacity).dblclick(function(){
                _this.close();
            }).appendTo('body').fadeIn(300);
            C = $(wBoxHtml).appendTo('body');
            handleClick();
        }
        /*
         * 处理点击
         * @param {string} what
         */
        function handleClick(){
            var con = C.find("#wBoxContent");
            if (_this.YQ.requestType && $.inArray(_this.YQ.requestType, ['iframe', 'ajax','img'])!=-1) {
                con.html("<div class='wBox_load'><div id='wBox_loading'><img src='"+_this.YQ.wBoxURL+"loading.gif' /></div></div>");                
                if (_this.YQ.requestType === "img") {
                    var img = $("<img />");
                    img.attr("src",_this.YQ.target);
                    img.load(function(){
                        img.appendTo(con.empty());
                        setPosition();
                    });
                }
                else 
                    if (_this.YQ.requestType === "ajax") {
                        $.get(_this.YQ.target, function(data){
                            con.html(data);
                            C.find('.wBox_close').click(_this.close);
                            setPosition();
                        })
                        
                    }
                    else {
                        if(_this.YQ.postdata!==null){
                            var url = _this.YQ.target + '?' + $.param(_this.YQ.postdata);
                        }else{
                            var url = _this.YQ.target;
                        }
                        var framehtml = "<div id='boxloading' style='text-align:center;margin-top:30px;'><img src='"+STATIC+"/global/images/wbox/blueload.gif'/></div>";
                        framehtml += "<iframe id='wBoxIframe' name='wBoxIframe' style='width:" + _this.YQ.iframeWH.width + "px;height:" + _this.YQ.iframeWH.height + "px;' scrolling='no' frameborder='0' src='" + url + "'></iframe>";
                        ifr = $(framehtml);
                        ifr.appendTo(con.empty());
                        ifr.load(function(){
                            try {
                                $('#boxloading').remove();
                                $it = $(this).contents();
                                $it.find('.wBox_close').click(_this.close);
                                $('.wBox_itemTitle').html($it.find('span:first').html());
                                $it.find('span:first').parent().remove();
                                fH = $it.height();//iframe height
                                fW = $it.width();
                                w = $win;
                                newW = Math.min(w.width() - 40, fW);
                                newH = w.height() - 25 - (_this.YQ.noTitle ? 0 : 30);
                                newH = Math.min(newH, fH);
                                newH = fH;
                                if (!newH) 
                                    return;
                                var lt = calPosition(newW,newH);
                                C.css({
                                    left: lt[0],
                                    top: lt[1]
                                });
                                
                                $(this).css({
                                    height: newH,
                                    width: newW
                                });
                            } 
                            catch (e) {
                            }
                        });
                    }
                
            }
            else 
                if (_this.YQ.target) {
                    $(_this.YQ.target).clone(true).show().appendTo(con.empty());
                    
                }
                else 
                    if (_this.YQ.html) {
                        con.html(_this.YQ.html);
                    }
                    else {
                        $t.clone(true).show().appendTo(con.empty());
                    }         
            afterHandleClick();
        }
        /*
         * 处理点击之后的处理
         */
        function afterHandleClick(){     
            setPosition();
            C.show().find('.wBox_close').click(_this.close).hover(function(){
                $(this).addClass("on");
            }, function(){
                $(this).removeClass("on");
            });
            $(document).unbind('keydown.wBox').bind('keydown.wBox', function(e){
                if (e.keyCode === 27) 
                    _this.close();
                return true
            });
            typeof _this.YQ.callBack === 'function' ? _this.YQ.callBack() : null;
            !_this.YQ.noTitle&&_this.YQ.drag?drag():null;
            if(_this.YQ.timeout){
                setTimeout(_this.close,_this.YQ.timeout);
            }
                
        }
        /*
         * 设置wBox的位置
         */
        function setPosition(){
            if (!C) {
                return false;
            }
            
            var width = C.width();
            var height= C.height();
            lt = calPosition(width,height);
            C.css({
                left: lt[0],
                top: lt[1]
            });
            var $h = $("body").height(), $wh = $win.height(),$hh=$(document).height();
            $h = Math.max($h, $wh);
            $h = Math.max($h,$hh);
            B.height($h).width($win.width())            
        }
        /*
         * 计算wBox的位置
         * @param {number} w 宽度
         */
        function calPosition(w,h){
            l = ($win.width() - w) / 2;
            //t = $win.scrollTop() + $win.height() /9;
            t = $win.scrollTop() + (h>=$win.height()?0:($win.height()-h)/2);
            if(t>30){
                t=t-30;
            }
            return [l, t];
        }
        /*
         * 拖拽函数drag
         */
        function drag(){
            var dx, dy, moveout;
            var T = C.find('.wBox_dragTitle').css('cursor', 'move');
            T.bind("selectstart", function(){
                return false;
            });
            
            T.mousedown(function(e){
                dx = e.clientX - parseInt(C.css("left"));
                dy = e.clientY - parseInt(C.css("top"));
                C.mousemove(move).mouseout(out).css('opacity', 0.8);
                T.mouseup(up);
            });
            /*
             * 移动改变生活
             * @param {Object} e 事件
             */
            function move(e){
                moveout = false;
                if (e.clientX - dx < 0) {
                    l = 0;
                }
                else 
                    if (e.clientX - dx > $win.width() - C.width()) {
                        l = $win.width() - C.width();
                    }
                    else {
                        l = e.clientX - dx
                    }
                C.css({
                    left: l,
                    top: e.clientY - dy
                });
                
            }
            /*
             * 你已经out啦！
             * @param {Object} e 事件
             */
            function out(e){
                moveout = true;
                setTimeout(function(){
                    moveout && up(e);
                }, 10);
            }
            /*
             * 放弃
             * @param {Object} e事件
             */
            function up(e){
                C.unbind("mousemove", move).unbind("mouseout", out).css('opacity', 1);
                T.unbind("mouseup", up);
            }
        }
        
        /*
         * 关闭弹出框就是移除还原
         */
        this.close=function (){
            $('.boxactiver').remove();
            $('.boxcloser').remove();
            if (C) {
                B.remove();
                C.stop().fadeOut(300, function(){
                    C.remove();
                })
            }
        }
        /*
         * 触发click事件
         */     
        $win.resize(function(){
            setPosition();
        });
        _this.YQ.show?_this.showBox():$t.click(function(){
            _this.showBox();
            return false;
        });
        return this;
    };
})(jQuery);
//****************************************************wbox.js end************************************************************************************************


//****************************************************jquery.jdbox.js begin************************************************************************************************
var jdbox = {

    iframe : function(url,data){
        $("body").append('<input class="boxactiver" style="display:none;"><input class="wBox_close boxcloser" style="display:none;">');
        $(".boxactiver:last").wBox({requestType: "iframe",target:url,postdata:data}).click();
    },

    confirm : function(title,content,back,cancelclick){
        $("body").append('<input class="boxactiver" style="display:none;"><input class="wBox_close boxcloser" style="display:none;">');
        if( typeof back != 'undefined' && back.indexOf("(") > 0 ){
            var html='<div style="padding:5px;width:250px;height:auto;color:#696969;font-size:12px;text-align:center;">'+content+'</div><div style="width:auto;height:auto;padding:10px;text-align:center;"><a href="javascript:;" onclick="jdbox.close();'+back+'"><img src="'+STATIC+'/global/images/wbox/fix_btn.jpg"/></a><a style="display:inline-block;height:25px;width:10px;"></a><a style="margin-left:10px;" href="javascript:;" onclick="jdbox.close();'+cancelclick+'"><img src="'+STATIC+'/images/index/fix_not_btn.jpg" /></a></div>';
        }else{
            var html='<div style="padding:5px;width:250px;height:auto;color:#696969;font-size:12px;text-align:center;">'+content+'</div><div style="width:auto;height:auto;padding:10px;text-align:center;"><a href="javascript:;" onclick="jdbox.close();'+back+'()"><img src="'+STATIC+'/global/images/wbox/fix_btn.jpg"/></a><a style="display:inline-block;height:25px;width:10px;"></a><a style="margin-left:10px;" href="javascript:;" onclick="jdbox.close();'+cancelclick+'"><img src="'+STATIC+'/images/index/fix_not_btn.jpg" /></a></div>';
        }
        $(".boxactiver:last").wBox({title:"<div id='title_tip' class='t_success'>"+title+"</div>",html:html}).click();
    },

    alert : function(type,content,back){
        var title = '';
        var msg = '';
        if(type==0){
            title = '<div id="title_tip" class="t_error">错误</div>';
            msg = '<div class="msg" style="background-image:url('+STATIC+'/global/images/wbox/icon_error.png);background-repeat:no-repeat;text-align:left;padding:1px 0 0 25px;height: 20px"><span>'+content+'</span></div>';
        }else if(type==1){
            title = '<div id="title_tip" class="t_success">成功</div>';
            msg = '<div class="msg" style="background-image:url('+STATIC+'/global/images/wbox/icon_right.png);background-repeat:no-repeat;text-align:left;padding:1px 0 0 25px;height: 20px"><span>'+content+'</span></div>';
        }else if(type==2){
            title = '<div id="title_tip" class="t_success">请等待...</div>';
            msg = '<div class="msg">'+(content?(content+'<br><br>'):'')+'<img src="'+STATIC+'/global/images/wbox/ajaxloading_01.gif" /></div>';
        }
        var html  = '<div style="padding:5px;width:250px;height:auto;text-align:center;">'+msg+'</div><div style="width:auto;height:auto;padding:10px;text-align:center;">';
        if(type != 2){
            html += '<a href="javascript:;" onclick="jdbox.close();'+back+'"><div class="sub_sure">确定</div></div>';
        }
        $("body").append('<input class="boxactiver" style="display:none;"><input class="wBox_close boxcloser" style="display:none;">');
        $(".boxactiver:last").wBox({title:title,html:html}).click();
    },
    video : function(content,title){
        title = '<div id="title_tip" class="t_success">'+title+'</div>';
        msg = '<div><span>'+content+'</span></div>';
        var html  = '<div style="padding:5px;width:570px;height:auto;text-align:center;">'+msg+'</div><div style="width:auto;height:auto;padding:10px;text-align:center;">';
        $("body").append('<input class="boxactiver" style="display:none;"><input class="wBox_close boxcloser" style="display:none;">');
        $(".boxactiver:last").wBox({title:title,html:html}).click();
    },
    close : function(){
        //$('#wBox_overlay').remove();
        //$('#wBox').remove();
        $(".wBox_close:last").click();
    }
}
//****************************************************jquery.jdbox.js end************************************************************************************************

//****************************************************jquery.base64.js begin************************************************************************************************

"use strict";jQuery.base64=(function($){var _PADCHAR="=",_ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_VERSION="1.0";function _getbyte64(s,i){var idx=_ALPHA.indexOf(s.charAt(i));if(idx===-1){throw"Cannot decode base64"}return idx}function _decode(s){var pads=0,i,b10,imax=s.length,x=[];s=String(s);if(imax===0){return s}if(imax%4!==0){throw"Cannot decode base64"}if(s.charAt(imax-1)===_PADCHAR){pads=1;if(s.charAt(imax-2)===_PADCHAR){pads=2}imax-=4}for(i=0;i<imax;i+=4){b10=(_getbyte64(s,i)<<18)|(_getbyte64(s,i+1)<<12)|(_getbyte64(s,i+2)<<6)|_getbyte64(s,i+3);x.push(String.fromCharCode(b10>>16,(b10>>8)&255,b10&255))}switch(pads){case 1:b10=(_getbyte64(s,i)<<18)|(_getbyte64(s,i+1)<<12)|(_getbyte64(s,i+2)<<6);x.push(String.fromCharCode(b10>>16,(b10>>8)&255));break;case 2:b10=(_getbyte64(s,i)<<18)|(_getbyte64(s,i+1)<<12);x.push(String.fromCharCode(b10>>16));break}return x.join("")}function _getbyte(s,i){var x=s.charCodeAt(i);if(x>255){throw"INVALID_CHARACTER_ERR: DOM Exception 5"}return x}function _encode(s){if(arguments.length!==1){throw"SyntaxError: exactly one argument required"}s=String(s);var i,b10,x=[],imax=s.length-s.length%3;if(s.length===0){return s}for(i=0;i<imax;i+=3){b10=(_getbyte(s,i)<<16)|(_getbyte(s,i+1)<<8)|_getbyte(s,i+2);x.push(_ALPHA.charAt(b10>>18));x.push(_ALPHA.charAt((b10>>12)&63));x.push(_ALPHA.charAt((b10>>6)&63));x.push(_ALPHA.charAt(b10&63))}switch(s.length-imax){case 1:b10=_getbyte(s,i)<<16;x.push(_ALPHA.charAt(b10>>18)+_ALPHA.charAt((b10>>12)&63)+_PADCHAR+_PADCHAR);break;case 2:b10=(_getbyte(s,i)<<16)|(_getbyte(s,i+1)<<8);x.push(_ALPHA.charAt(b10>>18)+_ALPHA.charAt((b10>>12)&63)+_ALPHA.charAt((b10>>6)&63)+_PADCHAR);break}return x.join("")}return{decode:_decode,encode:_encode,VERSION:_VERSION}}(jQuery));

//****************************************************jquery.base64.js end************************************************************************************************


//****************************************************jquery.easie.js begin************************************************************************************************

/*
 * Example usage:
 * $(elem).animate( {top: 100}, $.easie(0.25,0.1,0.25,1.0) );
 */
 
/*
 * jquery.easie.js:
 * http://www.github.com/jaukia/easie
 *
 * Version history:
 * 1.0.1 Semver versioning for jQuery plugins repository
 * 1.0.0 Initial public version
 *
 * LICENCE INFORMATION:
 *
 * Copyright (c) 2011 Janne Aukia (janne.aukia.com),
 * Louis-Rémi Babé (public@lrbabe.com).
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL Version 2 (GPL-LICENSE.txt) licenses.
 *
 * LICENCE INFORMATION FOR DERIVED FUNCTIONS:
 *
 * Function cubicBezierAtTime is written by Christian Effenberger, 
 * and corresponds 1:1 to the WebKit project function.
 * "WebCore and JavaScriptCore are available under the 
 * Lesser GNU Public License. WebKit is available under 
 * a BSD-style license."
 *
 */

/*jslint sub: true */

(function($) {
    "use strict";

    var prefix = "easie",
        ease = "Ease",
        easeIn = prefix+ease+"In",
        easeOut = prefix+ease+"Out",
        easeInOut = prefix+ease+"InOut",
        names = ["Quad","Cubic","Quart","Quint","Sine","Expo","Circ"];

    $.easie = function(p1x,p1y,p2x,p2y,name,forceUpdate) {
        name = name || [prefix,p1x,p1y,p2x,p2y].join("-");
        if ( !$.easing[name] || forceUpdate ) {
            // around 40x faster with lookup than without it in FF4
            var cubicBezierAtTimeLookup = makeLookup(function(p) {
                // the duration is set to 5.0. this defines the precision of the bezier calculation.
                // the animation is ok for durations up to 5 secs with this.
                // with the lookup table, the precision can be high without any big penalty.
                return cubicBezierAtTime(p,p1x,p1y,p2x,p2y,5.0);
            });
    
            $.easing[name] = function(p, n, firstNum, diff) {
                return cubicBezierAtTimeLookup.call(null, p);
            }
            $.easing[name].params = [p1x,p1y,p2x,p2y];
        }
        return name;
    }

    var $easie = $.easie;

    // default css3 easings

    $easie(0.000, 0.000, 1.000, 1.000, prefix+"Linear");
    $easie(0.250, 0.100, 0.250, 1.000, prefix+ease);
    $easie(0.420, 0.000, 1.000, 1.000, easeIn);
    $easie(0.000, 0.000, 0.580, 1.000, easeOut);
    $easie(0.420, 0.000, 0.580, 1.000, easeInOut);

    // approximated Penner equations, from:
    // http://matthewlein.com/ceaser/
    
    $easie(0.550, 0.085, 0.680, 0.530, easeIn+names[0]);
    $easie(0.550, 0.055, 0.675, 0.190, easeIn+names[1]);
    $easie(0.895, 0.030, 0.685, 0.220, easeIn+names[2]);
    $easie(0.755, 0.050, 0.855, 0.060, easeIn+names[3]);
    $easie(0.470, 0.000, 0.745, 0.715, easeIn+names[4]);
    $easie(0.950, 0.050, 0.795, 0.035, easeIn+names[5]);
    $easie(0.600, 0.040, 0.980, 0.335, easeIn+names[6]);
                    
    $easie(0.250, 0.460, 0.450, 0.940, easeOut+names[0]);
    $easie(0.215, 0.610, 0.355, 1.000, easeOut+names[1]);
    $easie(0.165, 0.840, 0.440, 1.000, easeOut+names[2]);
    $easie(0.230, 1.000, 0.320, 1.000, easeOut+names[3]);
    $easie(0.390, 0.575, 0.565, 1.000, easeOut+names[4]);
    $easie(0.190, 1.000, 0.220, 1.000, easeOut+names[5]);
    $easie(0.075, 0.820, 0.165, 1.000, easeOut+names[6]);
                    
    $easie(0.455, 0.030, 0.515, 0.955, easeInOut+names[0]);
    $easie(0.645, 0.045, 0.355, 1.000, easeInOut+names[1]);
    $easie(0.770, 0.000, 0.175, 1.000, easeInOut+names[2]);
    $easie(0.860, 0.000, 0.070, 1.000, easeInOut+names[3]);
    $easie(0.445, 0.050, 0.550, 0.950, easeInOut+names[4]);
    $easie(1.000, 0.000, 0.000, 1.000, easeInOut+names[5]);
    $easie(0.785, 0.135, 0.150, 0.860, easeInOut+names[6]);

    function makeLookup(func,steps) {
        var i;
        steps = steps || 101;
        var lookupTable = [];
        for(i=0;i<(steps+1);i++) {
            lookupTable[i] = func.call(null,i/steps);
        }
        return function(p) {
            if(p===1) return lookupTable[steps];
            var sp = steps*p;
            // fast flooring, see
            // http://stackoverflow.com/questions/2526682/why-is-javascripts-math-floor-the-slowest-way-to-calculate-floor-in-javascript
            var p0 = Math.floor(sp);
            var y1 = lookupTable[p0];
            var y2 = lookupTable[p0+1];
            return y1+(y2-y1)*(sp-p0);
        }
    }

    // From: http://www.netzgesta.de/dev/cubic-bezier-timing-function.html
    // 1:1 conversion to js from webkit source files
    // UnitBezier.h, WebCore_animation_AnimationBase.cpp
    function cubicBezierAtTime(t,p1x,p1y,p2x,p2y,duration) {
        var ax=0,bx=0,cx=0,ay=0,by=0,cy=0;
        // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
        function sampleCurveX(t) {return ((ax*t+bx)*t+cx)*t;}
        function sampleCurveY(t) {return ((ay*t+by)*t+cy)*t;}
        function sampleCurveDerivativeX(t) {return (3.0*ax*t+2.0*bx)*t+cx;}
        // The epsilon value to pass given that the animation is going to run over |dur| seconds. The longer the
        // animation, the more precision is needed in the timing function result to avoid ugly discontinuities.
        function solveEpsilon(duration) {return 1.0/(200.0*duration);}
        function solve(x,epsilon) {return sampleCurveY(solveCurveX(x,epsilon));}
        // Given an x value, find a parametric value it came from.
        function solveCurveX(x,epsilon) {var t0,t1,t2,x2,d2,i;
            function fabs(n) {if(n>=0) {return n;}else {return 0-n;}}
            // First try a few iterations of Newton's method -- normally very fast.
            for(t2=x, i=0; i<8; i++) {x2=sampleCurveX(t2)-x; if(fabs(x2)<epsilon) {return t2;} d2=sampleCurveDerivativeX(t2); if(fabs(d2)<1e-6) {break;} t2=t2-x2/d2;}
            // Fall back to the bisection method for reliability.
            t0=0.0; t1=1.0; t2=x; if(t2<t0) {return t0;} if(t2>t1) {return t1;}
            while(t0<t1) {x2=sampleCurveX(t2); if(fabs(x2-x)<epsilon) {return t2;} if(x>x2) {t0=t2;}else {t1=t2;} t2=(t1-t0)*0.5+t0;}
            return t2; // Failure.
        }
        // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
        cx=3.0*p1x; bx=3.0*(p2x-p1x)-cx; ax=1.0-cx-bx; cy=3.0*p1y; by=3.0*(p2y-p1y)-cy; ay=1.0-cy-by;
        // Convert from input time to parametric value in curve, then from that to output time.
        return solve(t, solveEpsilon(duration));
    }

})(jQuery);

//****************************************************jquery.easie.js end************************************************************************************************

//****************************************************jquery-cookie.js begin************************************************************************************************

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {expires: 0};
        if (value === null) {
            value = '';
            options = $.extend({}, options);
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//****************************************************jquery-cookie.js end************************************************************************************************

